using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cell : MonoBehaviour
{
    public bool selected = false;
    //声明selected公共布尔变量,默认为false
    public Material material_origin;
    //声明material_origin公共材质变量
    public bool is_useful = true;
    //声明is_useful公共布尔变量,默认为true
    void Start()
    //Start()方法在第一帧前调用
    {
        material_origin = new Material(gameObject.transform.GetComponent<Renderer>().material);
        //获取Renderer的默认材质,赋值给material_origin变量         
    }
    // Update is called once per frame
    void Update()
    //Update()方法每一帧调用一次 
    {
        if (Input.GetMouseButton(1))
        //如果按下右键,执行{}中的语句
        {
            gameObject.transform.GetComponent<Renderer>().material.color = material_origin.color;
            //将Render的材质颜色设置为material_origin的颜色 
            selected = false;
            //将selected设置为false
        }
    }
    private void OnMouseDown()
    //鼠标按下时调用
    {
        foreach (GameObject element in GameObject.FindGameObjectsWithTag("tank"))
        //使用foreach循环遍历所有标签为tank的游戏对象
        {
            if (element.GetComponent<tank>().selected == true)
            //如果当前遍历到的tank组件的selected变量为true,执行{}中的语句
            {
                selected = true;
                //将selected设置为true
            }
        }
    }
    private void OnMouseOver()
    //鼠标悬停时调用
    {
        gameObject.transform.GetComponent<Renderer>().material.color = Color.red;
        //将Render的材质颜色设置为红色     
    }
    private void OnMouseExit()
    //鼠标退出时调用
    {
        gameObject.transform.GetComponent<Renderer>().material.color = material_origin.color;
        //将Render的材质颜色设置为material_origin的颜色
    }

}